
package net.swa.index.service.impl;

import java.util.HashMap;
import java.util.Map;

import net.swa.index.beans.entity.Feedback;
import net.swa.index.beans.entity.Members;
import net.swa.index.service.FeedbackService;
import net.swa.index.util.ConstIndex;
import net.swa.system.dao.HibernateDaoSupport;
import net.swa.util.DateUtils;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.springframework.stereotype.Service;

@Service("feedbackService")
public class FeedbackServiceImpl extends HibernateDaoSupport implements FeedbackService
{

    private static final Logger log = Logger.getLogger(FeedbackServiceImpl.class);

    @Override
    public Map<String, Object> add(Long uid , String content)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        if (StringUtils.isBlank(content))
        {
            map.put("success", false);
            map.put("message", "内容不能为空");
            map.put("errorCode", ConstIndex.ERR_SOURCE);
            return map;
        }
        if (null != uid)
        {
            Session session = getCurrentSession();
            Members m = (Members) session.get(Members.class, uid);
            if (null != m)
            {
                Feedback model = new Feedback();
                model.setContent(content);
                model.setCreateTime(DateUtils.getCurrDate(null));
                model.setCreateUserId(uid);
                session.save(model);
                log.debug("成功添加反馈信息");
                map.put("success", true);
                map.put("message", "添加成功");
                map.put("errorCode", ConstIndex.ERR_NO);
            }
            else
            {
                map.put("success", false);
                map.put("errorCode", ConstIndex.ERR_TOKEN);
                map.put("message", "用户校验失败");
            }
        }
        else
        {
            map.put("success", false);
            map.put("errorCode", ConstIndex.ERR_TOKEN);
            map.put("message", "token校验失败");
        }
        return map;
    }

}